package com.yequan.designpattern.proxy.second_generation;

import com.yequan.designpattern.proxy.IGamePlayer;

import java.util.HashMap;
import java.util.Map;

public class GamePlayerProxy implements IGamePlayer {

    private IGamePlayer gamePlayer;
    private Map<String, IGamePlayer> gamePlayerMap = new HashMap<>();

//    public GamePlayerProxy(String username) {
//        try {
//            gamePlayer = new GamePlayer(this, username);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    public GamePlayerProxy() {

    }

    public void setGamePlayer(String username) {
        try {
            this.gamePlayer = new GamePlayer(this, username);
            gamePlayerMap.put(username, gamePlayer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void login(String account, String password) {
        gamePlayer.login(account, password);
    }

    @Override
    public void killBoss() {
        gamePlayer.killBoss();
    }

    @Override
    public void upgrade() {
        gamePlayer.upgrade();
    }

    public IGamePlayer getGamePlayer(String username) {
        return gamePlayerMap.get(username);
    }
}
